<template>
  <div class="table">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-cascades"></i> 签到日志
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <!-- <el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量删除</el-button> -->
        <!-- <el-select v-model="select_cate" placeholder="筛选省份" class="handle-select mr10">
          <el-option key="1" label="广东省" value="广东省"></el-option>
          <el-option key="2" label="湖南省" value="湖南省"></el-option>
        </el-select>-->
        <el-input v-model="select_word" placeholder="筛选关键词" class="handle-input mr10"></el-input>
        <el-button type="primary" icon="search" @click="search">搜索</el-button>
      </div>
      <el-table
        :data="checkData"
        border
        class="table"
        ref="multipleTable"
        @selection-change="handleSelectionChange"
      >
        <el-table-column prop="id" label="ID" sortable width="100" align="center"></el-table-column>
        <el-table-column prop="date" label="标识" width="100" align="center"></el-table-column>
        <el-table-column prop="name" label="姓名" width="150" align="center"></el-table-column>
        <el-table-column prop="department_name" label="部门" width="100" align="center"></el-table-column>
        <el-table-column prop="image_head_url" label="头像" width="200" align="center"></el-table-column>
        <el-table-column prop="create_time" label="添加时间" align="center"></el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          layout="prev, pager, next"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import * as api from "@/api/userApi.js";
export default {
  name: 'basetable',
  data() {
    return {
      url: './static/vuetable.json',
      checkData: [],
      departData: [], //部门数据,对应用户所在的部门
      total:0, //用户列表人数
      cur_page: 1,
      multipleSelection: [],
      select_cate: '',
      select_word: '',
      is_search: false,
      form: {
        name: '',
        date: '',
        address: ''
      },
      idx: -1
    }
  },
  created() {
    this.getOther();
  },
  methods: {
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getData(val);
    },
    // 获取 easy-mock 的模拟数据
    getData(page) {
      api.getSignLog({
        page: page
      })
        .then((res) => {
          if (res.code) {
            this.$message.error(res.message)
            return;
          }
          this.checkData = res.list.data
          if (!page) {
            this.total = res.total
          }
          console.log(res);
          this.checkData.forEach(d => {
            this.departData.forEach(d1 => {
              if (d1.id == d.department_id) {
                d.department_name = d1.name
              }
            })
            if (d.status == 0) {
              d.status = true
            } else {
              d.status = false
            }
          })
        })
    },
    async getOther() {
      await api.getDepartList()
        .then((res) => {
          this.departData = res.data.list
          console.log(res, '部门');
        })
      await this.getData();
    },
    search() {
      this.is_search = true;
      api.getSignLog({
        keywords: this.select_word
      })
        .then((res) => {
          const data = res.list.data
          this.checkData = data
          console.log(res);
        })
    },
    formatter(row, column) {
      return row.address;
    },
    filterTag(value, row) {
      return row.tag === value;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  }
}

</script>

<style scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}
.del-dialog-cnt {
  font-size: 16px;
  text-align: center;
}
.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #ff0000;
}
</style>
